<template>
  <div class="p-6">
    <el-card shadow="never" class="rounded-lg">
      <el-table :data="tableData" border>
        <el-table-column label="序号" type="index" width="70" align="center" />
        <el-table-column label="风险分析对象" prop="object" min-width="140" />
        <el-table-column label="风险分析单元" prop="unit" min-width="140" />
        <el-table-column label="岗位负责人" prop="postOwner" min-width="120" />
        <el-table-column label="隐患排查时间" prop="inspectTime" min-width="160" />
        <el-table-column label="计划排查时间" prop="planTime" min-width="160" />
        <el-table-column label="实际排查时间" prop="actualTime" min-width="160" />
        <el-table-column label="是否漏检" min-width="100" align="center">
          <template #default="scope">{{ scope.row.missed ? '是' : '否' }}</template>
        </el-table-column>
        <el-table-column label="是否产生隐患" min-width="120" align="center">
          <template #default="scope">{{ scope.row.hasDanger ? '是' : '否' }}</template>
        </el-table-column>
        <el-table-column label="隐患名称" prop="dangerName" min-width="160" />
        <el-table-column label="隐患类别" prop="dangerType" min-width="120" />
        <el-table-column label="是否整改完成" min-width="130" align="center">
          <template #default="scope">{{ scope.row.rectified ? '是' : '否' }}</template>
        </el-table-column>
        <template #empty>
          <el-empty description="暂无数据" />
        </template>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'

interface HiddenDangerRow {
  object: string
  unit: string
  postOwner: string
  inspectTime: string
  planTime: string
  actualTime: string
  missed: boolean
  hasDanger: boolean
  dangerName: string
  dangerType: string
  rectified: boolean
}

const tableData = ref<HiddenDangerRow[]>([])

const mockInit = () => {
  const objs = ['反应装置', '储罐区', '泵区', '管廊', '换热站']
  const units = ['反应釜', '储罐A', '循环泵', '主干管线', '板式换热器']
  const owners = ['王伟', '李娜', '张敏', '刘洋', '陈杰', '杨静', '黄磊', '周玲', '吴涛', '赵敏']
  const dangerNames = ['法兰渗漏', '阀门失灵', '保温破损', '支架松动', '油污堆积']
  const dangerTypes = ['设备类', '管线类', '管理类', '电气类']
  const list: HiddenDangerRow[] = []
  const n = 18 // 固定条数
  for (let i = 0; i < n; i++) {
    const month = (i % 9) + 1
    const day = String(5 + (i % 20)).padStart(2, '0')
    list.push({
      object: objs[i % objs.length],
      unit: units[i % units.length],
      postOwner: owners[i % owners.length],
      inspectTime: `2024-${String(month).padStart(2, '0')}-${day} 09:00`,
      planTime: `2024-${String(month).padStart(2, '0')}-${day} 09:00`,
      actualTime: `2024-${String(month).padStart(2, '0')}-${day} 10:30`,
      missed: i % 7 === 0,
      hasDanger: i % 4 === 0,
      dangerName: dangerNames[i % dangerNames.length],
      dangerType: dangerTypes[i % dangerTypes.length],
      rectified: i % 3 === 0,
    })
  }
  tableData.value = list
}

onMounted(() => mockInit())
</script>
